﻿{include file="public/header"/}
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header pcf10">
            <div class="layui-inline">
                <div class="layui-input-inline"><a class="layui-btn" href="javascript:;" id="checkVersion">
                <i class="layui-icon layui-icon-upload-circle"> </i>检查更新</a></div>
            </div>
            <div class="layui-inline fr">
                <div class="layui-input-inline"><a class="layui-btn refresh">
                <i class="layui-icon layui-icon-refresh-3"> </i></a></div>
            </div>
        </div>
        <div class="layui-card-body">
            <ul class="layui-timeline">
            {if($list)}
            {foreach $list as $value}
              <li class="layui-timeline-item">
                <i class="layui-icon layui-timeline-axis">&#xe63f;</i>
                <div class="layui-timeline-content layui-text">
                  <h3 class="layui-timeline-title">版本号：{$value.ver}</h3>
                  <p>更新日期：{$value.add_time}</p>
                  <p>更新文件数：{$value.files}</p>
                  <h4>更新内容：</h4>
                  <p>{$value.content|raw|default="暂无"}</p>
                </div>
              </li>
            {/foreach}
            {else/}
            暂无更新记录
            {/if}
            </ul>
        </div>
    </div>
</div>
{include file="public/loading"/}
{include file="public/footer"/}
<script type="text/javascript">
    layui.use(['jquery','layer'], function () {
        var $ = layui.jquery,
            layer = layui.layer;
        $("#checkVersion").click(function(){system_update();});
        $('.refresh').click(function(){location.reload();});
    })
    function system_update(){
        loading = parent.layer.msg('正在处理请勿刷新页面', {icon:16,shade:0.01,time:3600000});
        $.get("{:url('/upgrade/check_version')}", function(result){
            parent.layer.close(loading);
            if(result.code == 1) {
                parent.layer.confirm('有新的更新包('+result.data.last_version+')<br><font color="red">更新前请自行备份当前程序</font>',{title:'检查更新',btn:['开始更新','稍后更新'], closeBtn: 0},function(){
                    parent.layer.closeAll();
                    loading = parent.layer.msg('正在处理请勿刷新页面', {icon:16,shade:0.01,time:3600000});
                    $.get("{:url('/upgrade/system_update')}", function(res){
                        parent.layer.close(loading);
                        if(res.code == 1) {
                            parent.layer.alert(res.msg,{icon:1,closeBtn:0},function(index){
                                parent.location.reload();
                            });
                        } else {
                            parent.layer.alert(res.msg,{icon:2,closeBtn:0});
                        }
                    })
                })
            } else {
                parent.layer.msg(result.msg,{time:1000});
            }
        });
    }
</script>
</body>
</html>